﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Ledict.ConditionExtract.DAL;
using Ledict.ConditionExtract.Model;
namespace Ledict.ConditionExtract.BLL
{
    public class Express_WordBankRelBLL
    {
        Express_WordBankRelDAL dal = new Express_WordBankRelDAL();
        WordBankKeyWordsBLL wordbankkeywordsbll = new WordBankKeyWordsBLL();
        WordBankBLL wordbankbll = new WordBankBLL();

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string EW_ID, string WBK_ID)
        {
            return dal.Exists(EW_ID, WBK_ID);
        }

        public bool Add_Express_WordBankRel(string EWR_ID, string EW_ID, string WBK_ID)
        {
            return dal.Add_Express_WordBankRel(EWR_ID, EW_ID, WBK_ID);
        }

        public bool Add_Express_WordBankRel(List<SYS_Express_WordBankRel> bankrelList)
        {
            return dal.Add_Express_WordBankRel(bankrelList);
        }

        public DataTable Get_Express_WordBankRel(string EW_ID)
        {
            return dal.Get_Express_WordBankRel(EW_ID);
        }

        public bool Delete_Express_WordBankRel(string WBK_ID)
        {
            return dal.Delete_Express_WordBankRel(WBK_ID);
        }

        public bool AddList_Express_WordBankRel(string WBK_ID, string WordText)
        {
            return dal.AddList_Express_WordBankRel(WBK_ID, WordText);
        }
        /// <summary>
        /// 表述跑词库
        /// </summary>
        /// <param name="headword"></param>
        /// <param name="OneExpressWord"></param>
        /// <returns></returns>
        public List<string> WordBank(string headword, string OneExpressWord)
        {
            string dict_key = headword;
            if (dict_key == "") dict_key = "all";

            if (!StaticCacheBLL.WordBankWordTable.ContainsKey(dict_key))
            {
                DataTable dt = wordbankbll.GetWB_IDByHeadword(headword);//词库
                DataTable WordBankWorddt = new DataTable();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    WordBankWorddt.Merge(wordbankkeywordsbll.GetList_WB_IDNoOrder(dt.Rows[i]["WB_ID"].ToString()));                   
                }
                StaticCacheBLL.WordBankWordTable.Add(dict_key, WordBankWorddt);
            }
            List<string> result = new List<string>();
            DataTable WordBankWord = StaticCacheBLL.WordBankWordTable[dict_key];
            for (int j = 0; j < WordBankWord.Rows.Count; j++)
            {
                if (OneExpressWord.Contains(WordBankWord.Rows[j]["WBK_Word"].ToString()))
                    result.Add(WordBankWord.Rows[j]["WBK_ID"].ToString());
            }

            return result;
        }
    }
}
